package com.example.controller;

import com.example.entity.Team;
import com.example.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author fyxw
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/addUser")
    public ModelAndView addUser(@RequestParam("name") String username, @RequestParam String password) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("username", "传入的名字是：" + username);
        modelAndView.addObject("password", "传入的密码是：" + password);
        modelAndView.setViewName("view");
        return modelAndView;
    }

    @RequestMapping("findUser")
    public ModelAndView findUser(int id) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user", "你要查找的ID是：" + id);
        modelAndView.setViewName("view");
        return modelAndView;
    }

    @RequestMapping("delUser")
    public ModelAndView delUser(Integer id) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user", "你要删除的ID是：" + id);
        modelAndView.setViewName("view");
        return modelAndView;
    }

    @RequestMapping("/findAll")
    public ModelAndView findAllUser(int[] ids) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user", "你要查找的IDS是：" + Arrays.toString(ids));
        modelAndView.setViewName("view");
        return modelAndView;
    }

    @RequestMapping("/delAllUser")
    public ModelAndView delAllUser(@RequestParam List<Integer> ids) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user", "你要删除的ID是：" + ids);
        modelAndView.setViewName("view");
        return modelAndView;
    }

    @RequestMapping("addUserByMap")
    public ModelAndView adduserByMap(@RequestParam Map<String, String> user) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user", "你要增加的对象是：" + user);
        modelAndView.setViewName("view");
        return modelAndView;
    }

    @RequestMapping("addUserByEntity")
    public ModelAndView addUserByEntity(User user) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user", "传入的实体类:" + user);
        modelAndView.setViewName("view");
        return modelAndView;
    }

    @RequestMapping("addTeam")
    public ModelAndView addClass(Team team) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user", "传入的实体类:" + team);
        modelAndView.setViewName("view");
        return modelAndView;
    }
}
